package utils

import (
	"errors"

	"github.com/golang-jwt/jwt/v5"
)

type TokenClaims struct {
	UserId int `json:"userId"`
	jwt.RegisteredClaims
}

func ParseToken(tokenString, secret string) (*TokenClaims, error) {
	token, err := jwt.ParseWithClaims(tokenString, &TokenClaims{}, func(token *jwt.Token) (interface{}, error) {
		return []byte(secret), nil
	})
	if err != nil {
		return nil, err
	}

	if claims, ok := token.Claims.(*TokenClaims); ok && token.Valid {
		return claims, nil
	}
	return nil, errors.New("invalid token")
}

type AuthConfig struct {
	AccessSecret string
}
